//
//  HNSH_LevelViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/29.
//

#import "HNSH_LevelViewController.h"
#import "HNSH_LevelCell.h"

@interface HNSH_LevelViewController ()
/**  */
@property (nonatomic, strong) NSArray * dataArray;

@end

static NSString *HNSH_LevelCellID = @"HNSH_LevelCellID";

@implementation HNSH_LevelViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self showNavTitle:@"交易等级" showLeftItem:YES];
    
    [self.collectionView registerClass:[HNSH_LevelCell class] forCellWithReuseIdentifier:HNSH_LevelCellID];
        
    [self loadNewData];
}

- (void)loadNewData{
    [HNSH_UserNetServer requestPartnerPoundageConfigSuccess:^(ST_BaseNetModel * _Nullable responseObject) {
        [self.collectionView.mj_header endRefreshing];
        if (responseObject.code == 0) {
            NSArray * configs = responseObject.resultset[@"configs"];
            self.dataArray = [NSArray yy_modelArrayWithClass:HNSH_LevelModel.class json:configs];
            [self.collectionView reloadData];
        } else {
            [self.view makeToast:responseObject.msg];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: UICollectionViewDelegate Methods
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HNSH_LevelCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:HNSH_LevelCellID forIndexPath:indexPath];
    cell.model = [self.dataArray objectAtIndex:indexPath.row];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(kScreenWidth - 32, 70);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(16, 16, 16, 16);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

}

@end
